package xin.homeant.upms.service.impl;

import xin.homeant.upms.model.RolePermission;
import xin.homeant.cache.annotation.Cache;
import xin.homeant.cache.type.CacheOpType;
import xin.homeant.upms.dao.mapper.RolePermissionMapper;
import xin.homeant.upms.service.IPermissionService;
import xin.homeant.upms.service.IRolePermissionService;
import xin.homeant.upms.service.IUserService;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author homeant
 * @since 2017-05-01
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements IRolePermissionService {
	
	@Autowired
	private IUserService userService;
	
	@Autowired
	private IPermissionService permissionService;
	
	@Override
	@Cache(key="'RolePermissions'",expire=0,hfield="#args",opType=CacheOpType.READ_WRITE)
	public Set<String> getPermissionsByUsername(String username) {
		Set<Integer> roleIds = userService.getUserRolesByUsername(username);
		Set<Integer> permissionIds = baseMapper.getPermissionsByRoleIds(roleIds);
		return permissionService.getUserPermissions(permissionIds);
	}
	
}
